package com.aaa.java04;




import javax.sound.midi.Soundbank;
import java.util.Scanner;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/5 14:18
 * @description：课前测试
 * @modified By：
 * @version: 1.0
 */
public class BeforeTest {
    //add
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 计算两数之和
     * @create time: 2022/7/5 14:35
     * @param first second
     * @return int
     */
    public int add(int first,int second) {
        return first+second;
    }
    //subtract
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 计算两数之差
     * @create time: 2022/7/5 14:35
     * @param first second
     * @return int
     */
    public int subtract(int first,int second) {
        return first-second;
    }
    //multiply
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 计算两数乘积
     * @create time: 2022/7/5 14:35
     * @param first second
     * @return int
     */
    public int multiply(int first,int second) {
        return first*second;
    }
    //divide
    /**
     * @create by: Teacher陈（86521760@qq.com）
     * @description: 计算两数之商
     * @create time: 2022/7/5 14:35
     * @param first second
     * @return int
     */
    public int divide(int first,int second) {
        //判断除数是否为0
        if(second==0){
            System.out.println("除数不能为零，请重新输入");
            return 0;
        }
        return first/second;
    }
    /**
     * 主函数
     * @param args
     */
    public static void main(String[] args) {
        //实例化BeforeTest的对象
        BeforeTest beforeTest= new BeforeTest();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入运算符");
        String opt=scanner.next();
        System.out.println("请输入第一个数字：");
        int first = scanner.nextInt();
        System.out.println("请输入第二个数字：");
        int second = scanner.nextInt();
        //定义一个公共的结果
        int result=0;
        switch (opt){
            case "+":
                result = beforeTest.add(first, second);
                break;
            case "-":
                result = beforeTest.subtract(first, second);
                break;
            case "*":
                result = beforeTest.multiply(first, second);
                break;
            case "/":

                result = beforeTest.divide(first, second);
                break;
            default:
                System.out.println("不支持的运算");
        }

        System.out.println("结果是"+result);

    }
}
